package com.audi.handler;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.audi.box.objects.Authen;
import com.audi.box.objects.Devicestatus;
import com.audi.box.objects.LocalData;
import com.audi.box.objects.OJResponsive;

public class JSonparse {
	public static OJResponsive getrespon(String json) {
		OJResponsive result = new OJResponsive();
		try {
			JSONObject jObject = new JSONObject(json);
			result.setResult(jObject.getString("result"));
			result.setSuccess(jObject.getBoolean("issuccess"));
			result.setMess(jObject.getString("mess"));
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			Log.d("OJResponsive", "" + e);
		}
		return result;

	}

	public static Authen getauthen(String json) {
		Authen result = new Authen();
		Log.e("JSonparse", "Authen:" + json);
		try {
			JSONObject jObject = new JSONObject(json);
			Log.d("JSonparse", "Authen: in try 1");
			try {
				result.setTag(jObject.getString(LocalData.TAG));
				Log.d("JSonparse", "Authen: in try 2");
			} catch (Exception e) {

			}
			try {
				result.setSuccess(jObject.getBoolean(LocalData.TAG_SUCCESS));
				Log.d("JSonparse", "Authen: in try 3");
			} catch (Exception e) {

			}
			try {
				result.setUser_name(jObject.getString(LocalData.TAG_USERNAME));
			} catch (Exception e) {

			}

			try {
				result.setUser_group(jObject.getString(LocalData.TAG_USERGROUP));
				Log.d("JSonparse", "Authen: in try 4");
			} catch (Exception e) {

			}
			try {
				result.setUser_id(jObject.getString(LocalData.TAG_USERID));
				Log.d("JSonparse", "Authen: in try 5");
			} catch (Exception e) {

			}

		} catch (Exception e) {
			Log.e("JSonparse", "Authen parse error" + e);
		}
		return result;
	}

	public static Devicestatus getdevicestatus(String json) {
		Devicestatus result = new Devicestatus();
		Log.e("JSonparse", "Authen:" + json);
		try {
			JSONObject jObject = new JSONObject(json);
			Log.d("JSonparse", "Authen: in try 1");
			result.setDv0(jObject.getBoolean("0"));
			result.setDv1(jObject.getBoolean("1"));
			result.setDv2(jObject.getBoolean("2"));
			result.setDv3(jObject.getBoolean("3"));
		} catch (Exception e) {
			Log.e("JSonparse", "Authen parse error" + e);
		}
		return result;
	}
	
}
